<?php
/**
 * 
 * 获取评论插件
 * @author LeoNing
 *
 */
class CommentsDataProvider implements IDataProvider {
	public function provide($params) {
		global $_PAGE;
		$page_id = $_PAGE ['page_id'];
		extract ( $params );
		$wcM = new WebCommentModel ();
		$wcM->alias ( 'WCM' );
		$where ['deleted'] = 0;
		$where ['status'] = 'pass';
		// 分页
		if (isset ( $start )) {
			$start = intval ( $start );
			$start = $start < 1 ? 1 : $start;
		} else {
			$start = 1;
		}
		if (isset ( $limit )) {
			$limit = intval ( $limit );
			$limit = $limit < 1 ? 10 : $limit;
		} else {
			$limit = 10;
		}
		if (! isset ( $new )) {
			$where ['page_id'] = $page_id;
		}
		$wcM->sortDesc ( 'create_time' )->limit ( $limit, $start - 1 );
		if (isset ( $paging ) && $paging) {
			$wcM->count ( true );
		}
		$wcM->join ( 'web_page AS WP', "WCM.page_id = WP.page_id" );
		$wcM->join ('web_page_category as WPC',"WP.page_id = WPC.page_id");
		$wcM->where ( $where );
		$comments = $wcM->retrieve ( 'WCM.*,WP.title,WP.url,WP.subtitle,WPC.bind,WPC.home as domain_home' );
		if ($comments) {
			return new CtsDataSet ( $comments, $comments->countTotal, $limit );
		} else {
			return new CtsDataSet ( array (), 0, $limit );
		}
	}
}